package com.atguigu.util.method_fa;

/**
 * @author caesar
 * @date 2025/7/7
 * @Description:
 * @apiNote
 */
public class Product {
    private String productId;
    private String name;
    private double price;

    public Product() {
    }

    public Product(String productId, String name, double price) {
        this.productId = productId;
        this.name = name;
        this.price = price;
    }



    // Getter 和 Setter
    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public void applyDiscount(double discountRate) {
        if (discountRate > 0 && discountRate <= 1.0) {
            price *= discountRate;
        } else {
            System.out.println("折扣率无效，必须在 0~1 之间");
        }
    }

    @Override
    public String toString() {
        return "商品编号: " + productId + ", 名称: " + name + ", 价格: " + price;
    }
}
